class Bus {
  constructor() {
    this.busMap = {};  // 收集订阅
  }
  // 订阅
  $on(name, fn) {
    this.busMap[name] = this.busMap[name] || [];
    this.busMap[name].push(fn);
  }
  // 发布
  $emit(name, data) {
    if (this.busMap[name]) {
      this.busMap[name].forEach((fn) => {	fn(data);   });
    }
  }
  // 取消订阅
  $off(name) {
    if (this.busMap[name]) {
      delete this.busMap[name];
    }
  }
}
export default new Bus();

